<%--
  Created by IntelliJ IDEA.
  User: etund
  Date: 2014/9/20
  Time: 21:40
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>级联菜单</title>
    <script type="text/javascript" src="./xmFile.js"> </script>
</head>
<body>
<select id="province" name="province">
    <option value="">请选择....</option>
</select>
<select id="city" name="city">
    <option value="">请选择.....</option>
</select><html>
<head>
    <title>级联菜单</title>
    <script type="text/javascript" src="./xmFile.js"> </script>
</head>
<body>
<select id="province" name="province">
    <option value="">请选择....</option>
</select>
<select id="city" name="city">
    <option value="">请选择.....</option>
</select>
<script type="text/javascript">
  window.onload=function(){
      //得到服务器返回的xml文件
      var xhr = createXmlHttpRequest();
      xhr.onreadystatechange=function(){
          if(xhr.readyState==4){
              if(xhr.status==200||xhr.status==304){
                  var xmlDoc = xhr.responseXML;
                  //把省份的下拉菜单搞定
                  var xmlProvinceElements = xmlDoc.getElementsByTagName("province");
                  for(var i=0;i<xmlProvinceElements.length;i++){
                      //创建jsp中option
                      var optionElement = document.createElement("option");//<option></option>
                      optionElement.setAttribute("value",xmlProvinceElements[i].getAttribute("name"));
                      var textNode = document.createTextNode(xmlProvinceElements[i].getAttribute("name"));
                      optionElement.appendChild(textNode);
                      document.getElementById("province").appendChild(optionElement);
                  }
              }
          }
      }
        xhr.open("GET","/servlet/ServletDemo3?time="+new Date().getTime());
      xhr.send(null);
  }
  function createXmlHttpRequest(){
      var xmlHttp;
      try{    //Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
      }catch (e){
          try{    //Internet Explorer
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }catch (e){
              try{
                  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }catch (e){}
          }
      }
      return xmlHttp;
  }
</script>

</body>
</html>
